home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cmdline.lha / cmdline / src / cmd / shell_arg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-03  |  2.7 KB  |  102 lines

  1. //------------------------------------------------------------------------
  2. // ^FILE: shell_arg.h - define a shell-script command-line argument
  3. //
  4. // ^DESCRIPTION:
  5. //    This file defines the base class for all shell-script command
  6. //    line arguments.  In addition to inheriting from class CmdArg,
  7. //    a ShellCmdArg must also contain a variable-name, and its value.
  8. //
  9. // ^HISTORY:
  10. //    04/22/92    Brad Appleton    <brad@ssd.csd.harris.com>    Created
  11. //-^^---------------------------------------------------------------------
  12.  
  13. #ifndef  _shell_arg_h
  14. #define  _shell_arg_h
  15.  
  16. #include  <cmdargs.h>
  17.  
  18. #include  "shells.h"
  19.  
  20.    // All of our shell-script args will be ShellCmdArgs with two possible
  21.    // exceptions:
  22.    //   1) We may have a CmdArgUsage or
  23.    //   2) CmdArg::is_dummy() may return TRUE
  24.    //
  25.    // Hence, before we can downcast a CmdArg * to a ShellCmdArg *
  26.    // we must first make sure of the following:
  27.    //   1) is_dummy returns FALSE and that
  28.    //   2) CmdArg::GIVEN is set (if a CmdArgUsage was given then we would have
  29.    //      already exited!).
  30.    //
  31.  
  32. class  ShellCmdArg : public CmdArg {
  33. public:
  34.    ShellCmdArg(char    * variable_name,
  35.                char      optchar,
  36.                char    * keyword,
  37.                char    * value,
  38.                char    * description,
  39.                unsigned  syntax_flags =CmdArg::isOPTVALREQ);
  40.  
  41.    ShellCmdArg(char    * variable_name,
  42.                char      optchar,
  43.                char    * keyword,
  44.                char    * description,
  45.                unsigned  syntax_flags =CmdArg::isOPT);
  46.  
  47.    ShellCmdArg(char    * variable_name,
  48.                char    * value,
  49.                char    * description,
  50.                unsigned  syntax_flags =CmdArg::isPOSVALREQ);
  51.  
  52.    virtual ~ShellCmdArg(void);
  53.  
  54.       // Return the name of this variable/array
  55.    const char *
  56.    name(void) const { return  sca_name; }
  57.  
  58.       // Are we an array or a variable?
  59.    int
  60.    is_array(void) const;
  61.  
  62.       // Return the variable portion
  63.    ShellVariable &
  64.    variable(void)  { return  *shell_variable; }
  65.  
  66.       // Return the array portion
  67.    ShellArray &
  68.    array(void)  { return  *shell_array; }
  69.  
  70.       // If we are a variable then the "set" member function sets the
  71.       // value of the variable, otherwise it appends to the list of
  72.       // values of the array
  73.       //
  74.    void
  75.    set(const char * value);
  76.  
  77.    virtual  int
  78.    operator()(const char * & arg, CmdLine & cmd) = 0;
  79.  
  80. private:
  81.    ShellCmdArg(const ShellCmdArg & cp);
  82.  
  83.    ShellCmdArg &
  84.    operator=(const ShellCmdArg & cp);
  85.  
  86.    void
  87.    initialize(const char * name);
  88.  
  89.    union { 
  90.       ShellVariable *  shell_variable;
  91.       ShellArray    *  shell_array;
  92.    } ;
  93.  
  94.    char * sca_name;
  95.    char * sca_keyword;
  96.    char * sca_value;
  97.    char * sca_description;
  98. } ;
  99.  
  100. #endif  /* _shell_arg_h */
  101.  
  102.